<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('员工列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>姓名：</label>
                                <input type="text" name="name"/>
                            </li>
                            <li>
                                <label>性别：</label>
                                <select name="sex" id="sex" th:with="type=${@dict.getType('sys_user_sex')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>手机号码：</label>
                                <input type="text" name="phone"/>
                            </li>
                            <li>
                                <label>教育背景：</label>
                                <select name="education" th:with="type=${@dict.getType('employee_education')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>身份证号码：</label>
                                <input type="text" name="idCard"/>
                            </li>
                            <li>
                                <label>状态：</label>
                                <select name="status" id="status" th:with="type=${@dict.getType('employee_status')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>所属城市：</label>
			                    <select name="city" id="city" class="form-control " th:with="type=${@dict.getType('employee_city')}">
			                        <option value="">所有</option>
			                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
			                    </select>
                            </li>
                            <li>
                                <label>所属部门：</label>
                                <input name="departmentId" id="departmentId" class="form-control" type="hidden">
			                    <input onclick="selectDeptTree()" id="departmentName" type="text" placeholder="请选择归属部门"  >
                            </li>
                            <li>
                                <label>职位：</label>
                                <select name="position" id="position"  >
			                        <option value="">--请选择--</option>
			                        <option th:each="post:${posts}" th:value="${post.postId}" th:text="${post.postName}" th:disabled="${post.status == '1'}"></option>
			                    </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset();$('#departmentId').val('');"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="employee:employee:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="employee:employee:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="employee:employee:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="employee:employee:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('employee:employee:edit')}]];
        var removeFlag = [[${@permission.hasPermi('employee:employee:remove')}]];
        var prefix = ctx + "employee/employee";

        var sexMap = {};
        $('#sex option').each(function(i, n){
        	sexMap[$(n).val()] = $(n).text();
        });
        var statusMap = {};
        $('#status option').each(function(i, n){
        	statusMap[$(n).val()] = $(n).text();
        });
        var cityMap = {};
        $('#city option').each(function(i, n){
        	cityMap[$(n).val()] = $(n).text();
        });
        var positionMap = {};
        $('#position option').each(function(i, n){
        	positionMap[$(n).val()] = $(n).text();
        });
        
        

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "员工",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id', 
                    title: '主键ID',
                    visible: false
                },
                {
                    field: 'name', 
                    title: '姓名'
                },
                {
                    field: 'sex', 
                    title: '性别',
                    formatter: function(val, row, index){return sexMap[val];}
                },
                {
                    field: 'phone', 
                    title: '手机号码'
                },
                {
                    field: 'city', 
                    title: '所属城市',
                    formatter: function(val, row, index){return cityMap[val];}
                },
                {
                    field: 'departmentName', 
                    title: '所属部门'
                },
                {
                    field: 'position', 
                    title: '职位',
                    formatter: function(val, row, index){return positionMap[val];}
                },
                {
                    field: 'status', 
                    title: '状态',
                    formatter: function(val, row, index){return statusMap[val];}
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });       
        
        function selectDeptTree() {
        	var treeId = $("#treeId").val();
        	var deptId = $.common.isEmpty(treeId) ? "100" : $("#treeId").val();
        	var url = ctx + "system/dept/selectDeptTree/" + deptId;
			var options = {
				title: '选择部门',
				width: "380",
				url: url,
				callBack: doSubmit
			};
			$.modal.openOptions(options);
		}
		
		function doSubmit(index, layero){
			var tree = layero.find("iframe")[0].contentWindow.$._tree;
			if ($.tree.notAllowParents(tree)) {
				var body = layer.getChildFrame('body', index);
    			$("#departmentId").val(body.find('#treeId').val());
    			$("#departmentName").val(body.find('#treeName').val());
    			layer.close(index);
			}
		}
    </script>
</body>
</html>